--[[
    UI管理类
]]
local uIManager = BaseClass("uIManager")

function uIManager : __init()
    -- 查找组件
    local btnShop = GameObject.Find("BtnShop") : GetComponent("Button")
    local btnBag = GameObject.Find("BtnBag") : GetComponent("Button")
    local canvas = GameObject.Find("Canvas")
    -- 赋金币数量
    Global.CoinCount = 1000000

    -- 商店
    if btnShop ~= nil then
        btnShop.onClick : AddListener(function()
        print("UIManager输出1：打开商店界面")
        local shopPanel = GameObject.Instantiate(Resources.Load("UIPanel/ShopPanel"), canvas.transform)
        require("ShopManager").New(shopPanel)
            if shopPanel ~= nil then
                self.textPrice = shopPanel.transform:Find("TextPrice")
                self.textPrice = self.textPrice:GetComponent("Text")
                self.textPrice.text = "金币："..Global.CoinCount
                local shopBtnClose = shopPanel.transform : Find("BtnClose") : GetComponent("Button")
                if shopBtnClose ~= nil then
                    shopBtnClose.onClick : AddListener(function()
                    GameObject.Destroy(shopPanel)
                    end)
                else
                    print("UIManager输出2：没有找到ShopBtnClose按钮")
                end
                -- local btnBuy = shopPanel.transform : Find("BtnBuy") : GetComponent("Button")
                -- if btnBuy ~= nil then
                --     btnBuy.onClick : AddListener(function()
                --     print("UIManager输出3：购买成功")
                --     end)
                -- else
                --     print("UIManager输出4：没有找到BtnBuy按钮")
                -- end
            else
                print("UIManager输出5：没有找到ShopPanel")
            end
        end)
    else
        print("UIManager输出6：没有找到BtnShop按钮")
    end

    -- 背包
    if btnBag ~= nil then
        btnBag.onClick : AddListener(function()
        print("UIManager输出7：打开背包界面")
        local bagPanel = GameObject.Instantiate(Resources.Load("UIPanel/BagPanel"), canvas.transform)
            if bagPanel ~= nil then
                require("BagManager").New(bagPanel)
                local bagBtnClose = bagPanel.transform : Find("BtnClose") : GetComponent("Button")
                if bagBtnClose ~= nil then
                    bagBtnClose.onClick : AddListener(function()
                    GameObject.Destroy(bagPanel)
                    -- 格子清空
                    Global.BagCells = {}
                    end)
                else
                    print("UIManager输出8：没有找到BagBtnClose按钮")
                end
            else
                print("UIManager输出9：没有找到BagPanel")
            end
        end)
    else
        print("UIManager输出10：没有找到BtnBag按钮")
    end
end

return uIManager